home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / utils / stlogin4.lzh / SPAWN.C < prev    next >
C/C++ Source or Header  |  1993-09-10  |  2KB  |  67 lines

  1. /* various routines to run child processes Kees Lemmens 1993 */
  2.  
  3. #define MINT
  4.  
  5. #include <stdio.h>
  6. #include <process.h>
  7. #include <string.h>
  8. #include <osbind.h>    /* Pexec */
  9.  
  10. char *ux2dos(char *string)    /* convert / to \ */
  11. {    char *tmp;
  12.     while((tmp=strchr(string,'/')) != NULL)
  13.         *tmp='\\';
  14.     return string;
  15. }
  16.  
  17. /* NON standard, but very convenient ! */
  18.  
  19. int sspawnve(int mode,char *cmd, char *argstring, char **envp)
  20. {    long status;
  21.     char TosArgs[128] = "x";
  22.     int imode;
  23.     
  24. #ifdef DEBUG
  25.     mode = P_WAIT;
  26. #endif
  27.  
  28.     /* changing process group is not necessary, because we don't need
  29.        to exit the parent process. This is the responsibility of
  30.        the parent.
  31.     */
  32.     ux2dos(cmd);
  33.     ux2dos(argstring);
  34.  
  35.     strncat(TosArgs,argstring,sizeof(TosArgs) - 1);
  36.     *TosArgs = strlen(argstring);    /* first byte is strlen */
  37.  
  38.     switch(mode)
  39.     {    case P_WAIT    : imode=  0; break;
  40.         case P_NOWAIT  : imode=100; break;
  41.         case P_OVERLAY : imode=200; break;
  42.     }
  43.     
  44.     status = Pexec(imode, cmd, TosArgs, (void *)envp);
  45.  
  46.     return (status < 0L ? -1 : 0);
  47. }
  48.  
  49. int spawnve(int mode,char *cmd, char **argv, char **envp)
  50. {    static char CmdString[127];
  51.     char *ptr = CmdString;
  52.     int  spaceleft = (int)sizeof(CmdString) - 1;
  53.     
  54.     while(argv && *argv && spaceleft > 0 )
  55.     {    int len = (int)strlen(*argv);
  56.         strncpy(ptr,*argv,spaceleft);
  57.         ptr += len;
  58.         *ptr++ = ' ';    /* space is separator */
  59.         spaceleft -= len + 1;    /* also space counts ! */
  60.         argv++;        
  61.     }
  62.     return sspawnve(mode, cmd, CmdString, envp);
  63. }
  64.  
  65. int spawnv(int mode,char *cmd, char **argv)
  66. {    return spawnve(mode, cmd, argv, NULL);
  67. }